import scrapy
import json

from scrapy_redis.spiders import RedisCrawlSpider

from gkcxScrapy.items import GkcxscrapyItem




class GkcxspiderSpider(RedisCrawlSpider):
    name = 'gkcxspider'
    allowed_domains = ['gkcx.eol.cn']
    redis_key = "gkcx:starturl"

    def parse(self, response):

        body=json.loads(response.body)
        # 请求结果
        # message=body['message']
        # 学校名称
        name=body["data"]["name"]
        # 学校id
        school_id=body["data"]["school_id"]
        # 硕士点个数
        num_master=body["data"]["num_master"]
        # 博士点个数
        num_doctor=body["data"]["num_doctor"]
        # 国家特色学科个数
        num_subject=body["data"]["num_subject"]
        # 实验室个数
        num_lab=body["data"]["num_lab"]

        item = GkcxscrapyItem()

        item["name"] = name
        item["school_id"] = school_id
        item["num_master"] = num_master
        item["num_doctor"] = num_doctor
        item["num_subject"] = num_subject
        item["num_lab"] = num_lab
        print("---------------------------")

        yield item







